package cn.neusoft.service.impl;


import cn.neusoft.domain.ProviderInf;
import cn.neusoft.mapper.ProviderInfMapper;
import cn.neusoft.service.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ProviderImp implements ProviderService {

    @Autowired
    private ProviderInfMapper providerInfMapper;

    @Override
    public int providerRegister(ProviderInf providerInf) {
        int ans = 0;

        if(providerInf != null){
            if(providerInfMapper.findByName(providerInf.getName()) == null){
                ans = providerInfMapper.insert(providerInf);
            }
        }

        return ans;
    }

    @Override
    public int providerDelete(String name) {
        int ans = 0;

        if(name != null){
            if(providerInfMapper.findByName(name) != null){
                ans = providerInfMapper.deleteByName(name);
            }
        }

        return ans;
    }

    @Override
    public ProviderInf providerQuery(String name) {
        ProviderInf providerInf = null;

        if(name != null){
            providerInf = providerInfMapper.findByName(name);
        }

        return providerInf;
    }

    @Override
    public List<ProviderInf> providerQueryAll() {
        List<ProviderInf> list = null;

        list = providerInfMapper.getAll();

        return list;
    }

    @Override
    public int providerChange(ProviderInf providerInf) {
        int ans = 0;

        if(providerInf != null){
            ans = providerInfMapper.update(providerInf);
        }

        return ans;
    }

    @Override
    public ProviderInf getProviderByID(int id) {
        return providerInfMapper.findByID(id);
    }
}
